package com.fanqiechaodan.observer;

/**
 * @author fanqiechaodan
 * @Classname CurrentConditionsDisplay
 * @Description 实现观察者接口
 */
public class CurrentConditionsDisplay implements Observer {


    private float temperature;
    private float humidity;

    public CurrentConditionsDisplay(Subject weatherData) {
        weatherData.registerObserver(this);
    }

    /**
     * 通知观察者变化信息
     *
     * @param temperature
     * @param humidity
     */
    @Override
    public void update(float temperature, float humidity) {
        this.temperature = temperature;
        this.humidity = humidity;
        display();
    }

    private void display() {
        System.out.println("温度:" + temperature + "℃;湿度:" + humidity + "%");
    }
}
